<template>
	<view class="container">
		<view class="integrals-section">
			<view class="integrals">
				<view class="title">当前等级</view>
				<view class="value">Lv{{Tasks.level}}</view>
			</view>
			<view class="experience">
				<view class="row">经验值：{{Tasks.levelProgress}}/100</view>
				<view class="row" @tap="integralScores">
					<view>当前积分：{{Tasks.score}}</view>
					<image src="https://mp-cc85421a-533b-4b68-b797-f0a3eba335d0.cdn.bspapp.com/common/jump-r-arrow.png"
						class="jump-icon"></image>
				</view>
			</view>
		</view>
		<view class="experience-card">
			<view class="d-flex">
				<view class="level">Lv{{Tasks.level}}</view>
				<image src="https://mp-cc85421a-533b-4b68-b797-f0a3eba335d0.cdn.bspapp.com/common/icon_about.png"
					class="about-icon"></image>
			</view>
			<view>
				<view class="font-size-base">当前HT经验值: {{Tasks.levelProgress}}/100</view>
				<view class="process-box">
					<progress :percent="Tasks.levelProgress/100*100" border-radius="4px" :stroke-width="4"
						activeColor="#343434" backgroundColor="#D0D0D0" />
				</view>
			</view>
		</view>

		<view class="tasks-section">
			<view class="header">
				<view class="title">周期任务</view>
				<view class="subtitle">每天晚上12点过后重置</view>
			</view>
			<list-cell v-for="(item, index) in Tasks.tasks" :key="index">
				<view class="task">
					<view class="content">
						<view class="desc">{{ item.description }}</view>
						<view class="integral">
							<view class="text">积分</view>
							<view class="value">+{{ item.value }}</view>
						</view>
					</view>
					<view class="action">
						<template v-if="!item.isCompleted">
							<button type="primary" size="mini" @tap="gotoOK(index)">
								{{ item.id === 1 ? '签到' : '去完成' }}
							</button>
						</template>
						<template v-else>
							<image
								src="https://mp-cc85421a-533b-4b68-b797-f0a3eba335d0.cdn.bspapp.com/mall/me_club_task_img_done.png"
								class="completed-img"></image>
						</template>
					</view>
				</view>
			</list-cell>
		</view>
		<!-- <view class="tasks-section">
			<view class="header">
				<view class="title">成长任务</view>
			</view>
			<list-cell v-for="(task, index) in growTasks" :key="index">
				<view class="task">
					<view class="content">
						<view class="desc">{{ task.desc }}</view>
						<view class="integral">
							<view class="text">积分</view>
							<view class="value">+{{ task.value }}</view>
						</view>
					</view>
					<view class="action">
						<template v-if="!task.is_completed">
							<button :type="task.is_enable ? 'primary' : 'default'" 
									:disabled="!task.is_enable ? true : false" size="mini">
									去完成
							</button>
						</template>
						<template v-else>
							<image src="https://mp-cc85421a-533b-4b68-b797-f0a3eba335d0.cdn.bspapp.com/mall/me_club_task_img_done.png" class="completed-img"></image>
						</template>
					</view>
				</view>
			</list-cell>
		</view> -->
	</view>
</template>

<script>
	import listCell from '@/components/list-cell/list-cell.vue'
	import cloudApi from '../../common/cloudApi';
	import {
		mapState
	} from 'vuex'
	export default {
		components: {
			listCell
		},
		data() {
			return {
				Tasks: [],
				periodTasks: [{
						desc: '今日在季节限定消费一次',
						value: 10,
						is_completed: false,
						is_enable: false
					},
					{
						desc: '今日在热销榜消费一次',
						value: 10,
						is_completed: false,
						is_enable: true
					},
					{
						desc: '每日签到（奖励随机翻倍）',
						value: 5,
						is_completed: true,
						is_enable: false
					}
				]
			}
		},
		onShow() {
			this.getTask();
		},
		computed: {
			...mapState(['isLogin', 'userInfo'])
		},
		methods: {
			integralScores() {
				uni.navigateTo({
					url: '/pages/integrals/scores'
				})
			},
			async getTask() {
					await cloudApi.call({
						name: "users",
						data: {
							userId: this.userInfo.userId
						},
						success: (res) => {
							this.Tasks = res.result[0];
							console.log(this.Tasks)
						}
					});
			},
			gotoOK(i) {
				switch (i) {
					case 0:
						// 处理签到任务
						cloudApi.call({
							name: "updatesign",
							data: {
								userId: this.userInfo.userId,
							},
							success: () => {
								this.getTask();
							}

						});
						break;

					case 1:
						uni.switchTab({
							url: '/pages/index/index'
						})
						break;
					case 2:
						uni.switchTab({
							url: '/pages/index/index'
						})
						break;

					default:
						// 默认处理
						break;
				}

			}
		}
	}
</script>
<style>
	.experience-card {
		width: 100%;
		height: 270rpx;
		background-color: #ffffff;
		background: url('https://static.heytea.com/taro_trial/v1/img/my/member_benefits/me_rights_img_go.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		border-radius: $border-radius-lg;
		box-shadow: 0 0 20rpx 0 rgba($color: $border-color, $alpha: 0.4);
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 40rpx;
		margin-bottom: 40rpx;
	}

	.level {
		font-size: 40rpx;
		font-family: 'neutra';
		margin-right: 10rpx;
	}

	.process-box {
		margin-top: 10rpx;
		width: 50%;
	}

	.about-icon {
		width: 50rpx;
		height: 50rpx;
	}
</style>

<style lang="scss">
	.integrals-section {
		position: relative;
		margin-top: -100rpx;
		background: url('https://mp-cc85421a-533b-4b68-b797-f0a3eba335d0.cdn.bspapp.com/mall/me_img_banner_mall.png') no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 420rpx;
		padding: 30rpx 40rpx;
		padding-top: 130rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-start;
		margin-bottom: 20rpx;

		.integrals {
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			font-size: $font-size-sm;
			color: $text-color-base;

			.title {
				font-weight: bold;
			}

			.value {
				font-family: 'wenyue';
				color: #ffbc20;
				font-size: 42rpx;
				margin-top: 10rpx;
			}
		}

		.experience {
			display: flex;
			flex-direction: column;
			font-size: $font-size-medium;
			color: $text-color-grey;
			align-items: flex-start;

			.row {
				display: flex;
				align-items: center;

				.jump-icon {
					width: 32rpx;
					height: 32rpx;
				}
			}
		}
	}

	.tasks-section {
		background-color: $bg-color-white;
		margin-bottom: 20rpx;

		.header {
			display: flex;
			align-items: center;
			padding: 30rpx;

			.title {
				font-size: $font-size-lg;
				color: $font-size-base;
				font-weight: 500;
				margin-right: 20rpx;
			}

			.subtitle {
				font-size: $font-size-sm;
				color: $text-color-assist;
			}
		}

		.task {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.content {
				display: flex;
				flex-direction: column;
				align-items: flex-start;

				.desc {
					font-size: $font-size-medium;
					font-weight: 500;
					color: $text-color-base;
					margin-bottom: 10rpx;
				}

				.integral {
					display: flex;
					align-items: center;
					font-size: $font-size-sm;

					.text {
						color: $text-color-assist;
					}

					.value {
						color: $color-primary;
					}
				}
			}

			.action {
				button {
					border: 2rpx solid #edeeee !important;
					border-radius: 50rem !important;
					font-size: $font-size-sm;

					&.button-hover {
						opacity: 0.6;
					}
				}

				.completed-img {
					width: 100rpx;
					height: 100rpx;
				}
			}
		}
	}
</style>